import { defHttp } from '@/utils/http/axios';
import {
  IProductResult,
  IProductDetail,
  IProductManage,
  UnmounType,
  OfflineProductsLog,
} from './type';
import { BasicFetchResult } from '@/api/model/baseModel';
import { OPpublishStatus, ReviewStatus } from '@/enums/productManage';

enum Api {
  getProductList = '/mall/op/product-plaform-review-record/list',
  getProductManageList = '/mall/op/product/list',
  getProductDetail = '/mall/op/product-plaform-review-record/detail',
  getProductLibDetail = '/mall/op/product/detail',
  review = '/mall/op/product-plaform-review-record/review',
  getProductCategory = '/mall/op/product-category/getList',
  getUnmounTypeList = '/mall/op/product/unmounTypeList',
  updown = '/mall/op/product/updown',
  getUnmounRecordList = '/mall/op/product/unmounRecordList',
}

/**
 * 产品库列表
 * @param params
 * @returns
 */
export function getProductLibList(params) {
  return defHttp.get<BasicFetchResult<IProductManage>>({
    url: Api.getProductManageList,
    params,
  });
}

/**
 * 产品库列表详情
 * @param id
 * @returns
 */
export function getProductLibDetail(id: number) {
  return defHttp.get<IProductDetail>({
    url: Api.getProductLibDetail + '/' + id,
  });
}

/**
 * 查询失败原因选项
 * @returns
 */
export function getUnmounTypeList() {
  return defHttp.get<UnmounType[]>({
    url: Api.getUnmounTypeList,
  });
}

/**
 * 下架记录
 * @param params
 * @returns
 */
export function getUnmounRecordList(params:any, id: number) {
  return defHttp.get<BasicFetchResult<OfflineProductsLog>>({
    url: Api.getUnmounRecordList + '/' + id,
    params,
  });
}

/**
 * 上架或下架
 * @returns
 */
export function updown(data: {
  productIds: string[];
  opPublishStatus: OPpublishStatus;
  explain: string;
  unmounTypeId: number;
}) {
  return defHttp.post({
    url: Api.updown,
    data,
  });
}

//---------

/**
 * 审核列表
 * @param params
 * @returns
 */
export function getProductList(params) {
  return defHttp.get<BasicFetchResult<IProductResult>>({
    url: Api.getProductList,
    params,
  });
}

/**
 * 审核列表详情
 * @param id
 * @returns
 */
export function getProductDetail(id: number) {
  return defHttp.get<IProductDetail>({
    url: Api.getProductDetail + '/' + id,
  });
}

/**
 * 审核
 * @param data
 * @returns
 */
export function review(data: { id: number; reviewStatus: ReviewStatus; reviewContent?: string }) {
  return defHttp.post<IProductDetail>({
    url: Api.review,
    data,
  });
}

/**
 * 查询产品分类
 * @param level
 * @returns
 */
export function getProductCategory(level: number) {
  return defHttp.get<any>({
    url: Api.getProductCategory,
    data: { level },
  });
}
